package in.muton.edushare.academics.panels;

import in.muton.edushare.academics.panels.GradePanelUtil.GradeKeyHelper;
import in.muton.edushare.pages.EduShareBasePage;
import in.muton.edushare.pages.common.EdusharePanel;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;

public class EntityGradeView extends EdusharePanel {
	private EntityGradePanel parentPanel;

	public EntityGradeView(String id, EntityGradePanel panel,EduShareBasePage page, boolean editable) {
		super(id, page);
		this.parentPanel = panel;

		add(new Form<Void>("form"){
			@Override
			public void onSubmit(){
				parentPanel.setActiveMode(EntityGradePanel.EDIT_MODE);
			}
			private static final long serialVersionUID = 229755641521519916L;
		}.setVisible(editable));
		
		add(new ListView<GradeKeyHelper>("gradeList", parentPanel.getTupleList()) {
			@Override
			protected void populateItem(ListItem<GradeKeyHelper> arg0) {
				GradeKeyHelper t = arg0.getModelObject();
				arg0.add(new Label("gradeLetter", t.gradeName));
				arg0.add(new Label("minMarks", t.minMarks+""));
				arg0.add(new Label("maxMarks",t.maxMarks + ""));
				arg0.add(new Label("gpaValue", t.gpaValue+""));
				arg0.add(new Label("failGrade", t.passGrade?"":"F"));
			}
			private static final long serialVersionUID = 1L;
		});
	}
	
	@Override
	public boolean isVisible(){
		return parentPanel.getActiveMode() == EntityGradePanel.VIEW_MODE;
	}
	
	private static final long serialVersionUID = 4584825918185638366L;
}
